import java.util.*;
/**
 * 在这里给出对类 Player 的描述。
 * 
 * @作者（你的名字）
 * @版本（一个版本号或者一个日期）
 */
public class Player
{
    private int energy;
    private HashMap<String, Thing> bag = new HashMap<>();
     
    
    public void pick(Thing thing) {
        if (thing != null){
            bag.put(thing.getName(), thing);
            System.out.println("捡到了："+"["+thing.getName()+","+thing.getEnergy()+"]");
        }   
    }
    
    public Player() {
        this.energy = 50;
    }
    
    public void walk() {
        this.energy -= 5;    
    }
    
    public boolean isAlive() {
        return this.energy > 0;
    }
    
    public void check() {
        System.out.println("当前体力: " + energy);
    }
    
    public Thing getThing(String name) {
        return bag.get(name);
    }
    
    public void eat(String name) {
        Thing thing1 = getThing(name);

        if(thing1 != null) {
            
            int energy_before = energy;
            energy += thing1.getEnergy();
            bag.remove(name);
            if(energy > 100) {
                energy = 100;
            }
            System.out.println("吃掉：" + name +" "+"回复了"+(energy - energy_before)+"能量");
            check();
        }
        
    }
    
    public void eatInRoom(Thing thing) {
        this.energy += thing.getEnergy();
    }
    
    public void checkBag() {
        if (!bag.isEmpty()) {
            System.out.print("背包里有："); 
            for (String name : bag.keySet()) {
                System.out.println(name + " ");
            }
            //System.out.print(foods);
            System.out.println();
        }
        else {
            System.out.println("背包里没有东西。");
        }
    }
    
    public String getThingKey(HashMap<String,Thing> map, Thing value) {
        String key = null;//Map,HashMap并没有实现Iteratable接口.不能用于增强for循环.
        for(String getKey: map.keySet()){
            if(map.get(getKey).equals(value)){
                 key = getKey;
            }
        }
        return key;
        //这个key肯定是最后一个满足该条件的key.
    }
    
    public boolean isNess(Thing name) {
        if(getThingKey(bag, name) == "bedsheet") {
            return true;
        }
        else {
            return false;
        }
    }
}
